package com.bogo.webhook.service.impl;

import com.bogo.webhook.feign.BaiduWenxinService;
import com.bogo.webhook.feign.TulingRobotService;
import com.bogo.webhook.feign.request.TulingRequest;
import com.bogo.webhook.feign.request.WenxinRequest;
import com.bogo.webhook.feign.response.TulingResponse;
import com.bogo.webhook.feign.response.WenxinResponse;
import com.bogo.webhook.service.RobotChatService;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

@Service
@Primary
public class WenxinChatServiceImpl implements RobotChatService {

    @Resource
    private BaiduWenxinService baiduWenxinService;

    @Value("${baidu.wenxin.client-id}")
    private String clientId;

    @Value("${baidu.wenxin.app-key}")
    private String appId;

    @Value("${baidu.wenxin.secret-key}")
    private String secretKey;

    @Override
    public String get(String text, String userId) {
        WenxinRequest request = new WenxinRequest();
        request.setMessage(text);
        request.setOpenId(userId);
        request.setSource(clientId);
        WenxinResponse response = baiduWenxinService.get(appId, secretKey, request);
        return response.getText();
    }
}
